﻿#ifndef SQLCOMMON_H
#define SQLCOMMON_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlError>
#include <QDebug>
#include <QSqlQuery>
#include <QVariantList>
#include <QMessageBox>

#pragma execution_character_set("utf-8")


class SqlCommon : public QObject {
    Q_OBJECT
public:
    explicit SqlCommon(QObject *parent = nullptr);
    ~SqlCommon();

    bool openDatabase(const QString &dbPath); // 打开数据库
    QSqlQueryModel* getTableModel_material(QObject *parent = nullptr); // 返回
    bool insertData_material(int materialNum, const QString &materialName, double temperature, double emissivity);
    bool updateData_material(int materialNum, const QString &materialName, double temperature, double emissivity);
    bool deleteData_material(int materialNum);
    QSqlQueryModel *getTableModel_modin(QObject *parent);
private:
    QSqlDatabase db;
    bool executeQuery(const QString &queryStr, const QVariantList &args);
    QSqlQuery selectQuery(const QString &queryStr);
};

#endif // SQLCOMMON_H
